package com.opennews.openplatform

import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Value

@CompileStatic
class AppReleaseLogController extends BaseController {
    @Value('${openplatform.resource.httpBaseUrl}')
    String httpBaseUrl

    @Value('${openplatform.resource.h5DirectoryName}')
    String h5DirectoryName

    AppReleaseLogService appReleaseLogService
    
    // region: Get actions.
    def index() {
        render("AppReleaseLogController")
    }

    def queryByAppVersion() {
        def appVersion = params.appVersion.toString()
        def result = appReleaseLogService.queryByAppVersion(appVersion)

        sendDataResponse(result)
    }

    def queryLatestVersion() {
        def appVersion = params.appVersion.toString()
        def result = appReleaseLogService.queryLatestVersion(appVersion)

        sendDataResponse([
            hasUpdate: result != null,
            appInfo: result,
            sharingH5Url: "$httpBaseUrl/$h5DirectoryName/app-sharing.html"
        ])
    }

    def listChangeLog() {
        def pageSize = params.int("pageSize")
        def pageIndex = params.int("pageIndex")
        def result = appReleaseLogService.listChangeLog(pageSize, pageIndex)

        sendDataResponse(result)
    }
    // endregion
}